# Untitled - By: 23602 - 周六 3月 8 2025

import sensor, image, time, lcd
from modules import ybkey
lcd.init()                          # Init lcd display
lcd.clear(lcd.RED)                  # Clear lcd screen.
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()
key = ybkey();
i = 0
while(True):
    clock.tick()
    img = sensor.snapshot()
    lcd.display(img)
    keyState = key.is_press();
    if keyState == 0:
        continue
    time.sleep(0.5)
    file_name = "/sd/images/" + str(i + 180) + ".jpg"
    i += 1
    img.save(file_name)
    lcd.clear(lcd.BLUE)
    log_str = "save " + file_name + "success"
    lcd.draw_string(30, 30, log_str, lcd.WHITE, lcd.BLUE)
    while True:
        flag = key.is_press()
        if flag == 1:
            print("have key press2")
            time.sleep(0.5)
            break
